# -*- coding: utf-8 -*-
# @Time    : 2020/6/22 10:48
# @Author  : VillageTony
# @Email   : diaoyongcheng392@163.com
# @File    : Three_level_linkage.py
# @Software: PyCharm
from odoo import models, fields, api


class CountryCity(models.Model):
    _name = 'country.city'
    _description = "城市模型"

    state_id = fields.Many2one('res.country.state', string='省份')
    name = fields.Char(string='城市名称', required=True)
    ext = fields.Char(string='扩展id', default='0')


class CountryArea(models.Model):
    _name = 'country.area'
    _description = "区信息"

    city_id = fields.Many2one('country.city', string='城市')
    name = fields.Char(string='所在区', required=True)
    ext = fields.Char(string='扩展id', default='0')

#
# class ResPartner(models.Model):
#     _inherit = 'res.partner'
#     state_id = fields.Many2one('res.country.state')
#     city_id = fields.Many2one('res.country.city', string='市')
#     area_id = fields.Many2one('res.country.area', string='区')
#
#     @api.onchange('state_id')
#     def _onchange_state_id(self):
#         # 作用是当改变省时，清空市和区
#         self.city_id = False
#         self.area_id = False
#         if self.state_id:
#             return {'domain': {'city_id': [('state_id', '=', self.state_id.id)]}}
#         else:
#             return {'domain': {'city_id': []}}
#
#     @api.onchange('city_id')
#     def _onchange_city_id(self):
#         self.area_id = False
#         if self.city_id:
#             return {'domain': {'area_id': [('city_id', '=', self.city_id.id)]}}
#         else:
#             return {'domain': {'area_id': []}}
